/**
 * @(#)Attachement.java Jan 15, 2010
 *   
 * Copyright  (c) 2009-2010 Wilmar IT Service,  Inc.   
 * All  rights  reserved.   
 * TODO
 */

package com.wilmar.process.entity;

import java.io.Serializable;
import java.net.URI;
import java.util.Date;

/**
 * 工作流附件实体
 * 
 * @author makubex Email:makubexnet@gmail.com
 * @version 1.0.0
 */
public class Attachement implements Serializable, Comparable<Attachement> {

	/**
	 * @serialField
	 */
	private static final long serialVersionUID = -6983265889061416190L;

	private URI downloadUrl;
	private String displayName;
	private String businessKey;
	private Date uploadTime;

	/**
	 * 完整构造函数
	 * 
	 * @param downloadUrl
	 *            附件下载的url地址
	 * @param displayName
	 *            附件名称
	 * @param businessKey
	 *            业务关键字
	 * @param uploadTime
	 *            上传时间
	 */
	public Attachement(URI downloadUrl, String displayName, String businessKey,
			Date uploadTime) {
		super();
		this.downloadUrl = downloadUrl;
		this.displayName = displayName;
		this.businessKey = businessKey;
		this.uploadTime = uploadTime;
	}

	/**
	 * 构造函数
	 * 
	 * @param downloadUrl
	 *            附件下载的url地址
	 * @param displayName
	 *            附件名称
	 */
	public Attachement(URI downloadUrl, String displayName) {
		super();
		this.downloadUrl = downloadUrl;
		this.displayName = displayName;
	}

	/**
	 * @return the displayName
	 */
	public String getDisplayName() {
		return displayName;
	}

	/**
	 * @param displayName
	 *            the displayName to set
	 */
	public void setDisplayName(String displayName) {
		this.displayName = displayName;
	}

	/**
	 * @return the businessKey
	 */
	public String getBusinessKey() {
		return businessKey;
	}

	/**
	 * @param businessKey
	 *            the businessKey to set
	 */
	public void setBusinessKey(String businessKey) {
		this.businessKey = businessKey;
	}

	/**
	 * @return the downloadUrl
	 */
	public URI getDownloadUrl() {
		return downloadUrl;
	}

	/**
	 * @param downloadUrl
	 *            the downloadUrl to set
	 */
	public void setDownloadUrl(URI downloadUrl) {
		this.downloadUrl = downloadUrl;
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((businessKey == null) ? 0 : businessKey.hashCode());
		result = prime * result
				+ ((displayName == null) ? 0 : displayName.hashCode());
		result = prime * result
				+ ((downloadUrl == null) ? 0 : downloadUrl.hashCode());
		return result;
	}

	/**
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Attachement other = (Attachement) obj;
		if (businessKey == null) {
			if (other.businessKey != null)
				return false;
		} else if (!businessKey.equals(other.businessKey))
			return false;
		if (displayName == null) {
			if (other.displayName != null)
				return false;
		} else if (!displayName.equals(other.displayName))
			return false;
		if (downloadUrl == null) {
			if (other.downloadUrl != null)
				return false;
		} else if (!downloadUrl.equals(other.downloadUrl))
			return false;
		return true;
	}

	/**
	 * @return the uploadTime
	 */
	public Date getUploadTime() {
		return uploadTime;
	}

	/**
	 * @param uploadTime
	 *            the uploadTime to set
	 */
	public void setUploadTime(Date uploadTime) {
		this.uploadTime = uploadTime;
	}

	/**
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
	 */
	public int compareTo(Attachement arg0) {
		if (this.uploadTime == null)
			return -1;
		else if (arg0.uploadTime == null)
			return 1;
		else if (this.uploadTime.before(arg0.getUploadTime()))
			return 1;
		else if (this.uploadTime.after(arg0.getUploadTime()))
			return -1;
		else
			return 0;
	}

}
